package com.cskaoyan.service.user.impl;

import com.cskaoyan.bean.common.BasePageInfo;
import com.cskaoyan.bean.common.CommonData;
import com.cskaoyan.bean.po.MarketFeedback;
import com.cskaoyan.bean.po.MarketFeedbackExample;
import com.cskaoyan.mapper.MarketFeedbackMapper;
import com.cskaoyan.service.user.UserFeedbackService;
import com.cskaoyan.util.StringUtil;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author jzp
 * @since 2022/11/20 17:18
 */
@Service
public class UserFeedbackServiceImpl implements UserFeedbackService {
    @Autowired
    MarketFeedbackMapper marketFeedbackMapper;

    @Override
    public CommonData list(BasePageInfo info, String username, String id) {
        PageHelper.startPage(info.getPage(), info.getLimit());

        MarketFeedbackExample example = new MarketFeedbackExample();
        MarketFeedbackExample.Criteria criteria = example.createCriteria();
        if (!StringUtil.isEmpty(username)) {
            criteria.andUsernameLike("%" + username.trim() + "%");
        }
        if (!StringUtil.isEmpty(id)) {
            try {
                criteria.andIdEqualTo(Integer.valueOf(id));
            }catch (Exception e){
                return null;
            }

        }
        example.setOrderByClause(info.getSort() + " " + info.getOrder());
        List<MarketFeedback> marketFeedback = marketFeedbackMapper.selectByExample(example);

        PageInfo<MarketFeedback> pageInfo = new PageInfo<>(marketFeedback);
        return CommonData.data(pageInfo);
    }
}
